<template>
    <div>
        <el-table :data="goodslist" border style="width: 100%">
            <el-table-column prop="id" label="商品编号" width="100">
            </el-table-column>
            <el-table-column prop="goodsname" label="商品名称" width="80">
            </el-table-column>
            <el-table-column prop="price" label="商品价格">
            </el-table-column>
            <el-table-column prop="market_price" label="市场价格">
            </el-table-column>
            <el-table-column  label="图片">
                <template slot-scope="item">
                    <div>
                        <img style="width: 40px; height: 40px;" :src="item.row.img" alt="">
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="是否新品">
                <template slot-scope="item">
                    <div>
                        <el-button type="success" size="mini" plain>{{ item.row.isnew == 1 ? '是' : '否' }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="是否热卖">
                <template slot-scope="item">
                    <div>
                        <el-button type="success" size="mini" plain>{{ item.row.ishot == 1 ? '是' : '否' }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template slot-scope="item">
                    <div>
                        <el-button type="success" plain size="mini">{{ item.row.status == 1 ? '正常' : '禁用' }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" circle size="mini"
                            @click="edit(item.row.id)"></el-button>
                        <el-button type="danger" icon="el-icon-delete" circle size="mini"
                            @click="del(item.row.id)"></el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页
        page-size	每页显示条目个数，支持 .sync 修饰符	number	—	10
        total	总条目数	number	—	—
        current-change	currentPage 改变时会触发	当前页
        -->
        <el-pagination background layout="prev, pager, next" @current-change="changepage" :page-size="size" :total="total">
        </el-pagination>
    </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { goodsdelete } from '@/request/api';
export default {
    data() {
        return {
        }
    },
    methods: {
        // 切换页码触发
        changepage(index) {
            this.$store.dispatch('goods/GetPageInfo',index)
        },
        // 编辑
        edit(id) {
            this.$emit('edit',id)
        },
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                goodsdelete({ id }).then(res => {
                    if (res.code == 200) {
                        this.$store.dispatch('goods/GetGoodsInfo')
                        this.$store.dispatch('goods/GetCountInfo')
                        this.$message.success(res.msg)
                    }else{
                        this.$message.error(res.msg)
                    }
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    },
    mounted() {
        this.$store.dispatch('goods/GetGoodsInfo')
        this.$store.dispatch('goods/GetCountInfo')
    },
    watch: {},
    computed: {
        ...mapGetters({
            size: 'goods/getSize',
            total: 'goods/getCount',
            goodslist: 'goods/getGoods'
        })
    },
    filters: {},
    components: {}
}
</script>
<style scoped>
.el-pagination {
    position: absolute;
    right: 10px;
}
</style>